// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Author: Markus Gutschke

#ifndef JSON_H__
#define JSON_H__

#include <sys/types.h>

#include "hashmap.h"

enum JSONType { J_STRING, J_NUMBER, J_ARRAY, J_OBJECT,
                J_FALSE, J_TRUE, J_NULL };

struct JSON {
  enum JSONType    type;
  union {
    char           *str;
    double         number;
    struct {
      struct JSON  *array;
      size_t       array_size;
    };
    struct HashMap obj;
  };
};

struct JSON *newJSON(const char *txt);
void initJSON(struct JSON *json, const char *txt);
void destroyJSON(struct JSON *json);
void deleteJSON(struct JSON *json);
void updateJSONValue(struct JSON *json, const char *key, const char *value);
int isEqualJSON(const struct JSON *a, const struct JSON *b,
                const struct HashMap *exclude);

#endif  // JSON_H__
